package com.ws.exer;

public class FamilyAccount {

    public static void main(String[] args) {
        int wealth = 10000; //初始金额
        boolean isFlag = true;
        String details = ""; //用于记录用户的收入和支出详情
        while (isFlag) {
            System.out.println("————————————————————家庭收支记账软件——————————————————");
            System.out.println("                    1 收支明细");
            System.out.println("                    2 登记收入");
            System.out.println("                    3 登记支出");
            System.out.println("                    4 退    出");
            System.out.println("                   请选择（1~4）：");

            //获取用户的选择：
            char select = Utility.readMenuSelection();
            switch (select) {
                case '1':
                    System.out.println("————————————————————当前收支明细记录————————————————————");
                    System.out.println("收支\t\t账户金额\t\t\t收支金额\t\t\t说   明");
                    System.out.println(details);
                    System.out.println("———————————————————————————————————————————————————————");
                    break;
                case '2':
                    System.out.println("本次收入金额：");
                    int addMoney = Utility.readNumber();
                    System.out.println("本次收入说明：");
                    String info = Utility.readString();
                    wealth += addMoney;
                    details += "收入\t\t" + wealth + "\t\t\t" + addMoney + "\t\t\t\t" + info + "\n";
                    System.out.println("—————————————————————————登记完成——————————————————————————");
                    break;
                case '3':
                    System.out.println("本次支出金额：");
                    int payMoney = Utility.readNumber();
                    if (wealth < payMoney) {
                        System.out.println("支付失败，超出账户金额");
                    }  else {
                        System.out.println("本次支出说明：");
                        String info2 = Utility.readString();
                        wealth -= payMoney;
                        details += "支出\t\t" + wealth + "\t\t\t" + payMoney + "\t\t\t\t" + info2 + "\n";
                    }
                    break;
                case '4':
                    System.out.println("确认是否推出（Y/N）：");
                    char confirmSelection = Utility.readConfirmSelection();
                    if (confirmSelection == 'Y') {
                        isFlag = false;
                    }
                    break;
            }

        }
    }
}
